
#include "msg_queue.h"

std::string zs::CMsgQueue::pop_msg()
{
    std::unique_lock<std::mutex> locker(mutex_);
    cond_.wait(locker, [this] { return !msg_queue_.empty(); });
    std::string msg = msg_queue_.front();
    msg_queue_.pop();
    return msg;
}

void zs::CMsgQueue::push_msg(const std::string &msg)
{
    std::lock_guard<std::mutex> locker(mutex_);
    if (msg_queue_.size() >= max_size_)
    {
        msg_queue_.pop();
    }
    msg_queue_.push(msg);
    cond_.notify_one();
}
